package com.sunday.android.fangdaifu.bukong.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.sunday.android.fangdaifu.bukong.R;
import com.sunday.android.fangdaifu.bukong.activity.index.BuilderDetailActivity;
import com.sunday.android.fangdaifu.bukong.entity.IndexProjectDetail;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by yun_sheng on 2017/7/20.
 */

public class IndexItemAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private Context context;
    private List<IndexProjectDetail.ListBean> beanList;

    public IndexItemAdapter(Context context, List<IndexProjectDetail.ListBean> beanList) {
        this.context = context;
        this.beanList = beanList;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.index_item_detail, parent, false);
        return new ItemHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ItemHolder itemHolder = (ItemHolder) holder;
        final IndexProjectDetail.ListBean bean = beanList.get(position);
        itemHolder.tvName.setText(bean.getHouseName());
        itemHolder.tvAddress.setText(bean.getAddress());
        itemHolder.tvEquipment.setText(String.format("倾斜 %d   沉降 %d   裂缝(位移) %d",bean.getHorizontal(),bean.getSettlement(),bean.getCrack()));
        itemHolder.lMain.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, BuilderDetailActivity.class);
                intent.putExtra("id",bean.getId());
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return beanList.size();
    }

    //item view
    class ItemHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.tvName)
        TextView tvName;
        @Bind(R.id.lMain)
        View lMain;
        @Bind(R.id.tvAddress)
        TextView tvAddress;
        @Bind(R.id.tvEquipment)
        TextView tvEquipment;
        public ItemHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

}
